import SettingPanel, { SettingPanelType } from "./SettingPanel";
import TipPanel from "./TipPanel";
import GameManager, { GameState, GameType } from "../Manager/GameManager";


const {ccclass, property} = cc._decorator;

@ccclass
export default class GamePlayPanel extends cc.Component {
    public static Instance:GamePlayPanel;

    @property(cc.Button)
    Button_pause:cc.Button = null;
    
    @property(cc.Label)
    Label_score:cc.Label = null;

    @property(cc.Label)
    Label_highScore:cc.Label = null;

    onLoad () {
        GamePlayPanel.Instance = this;
        cc.log("onLoad*--");
    }

    start () {
        this.Button_pause.node.on('click', this.click_pause, this);
    }

    ShowOn()
    {
        this.node.active = true;

        if (cc.sys.platform == cc.sys.WECHAT_GAME) {
            wx.getOpenDataContext().postMessage({
                msg: 'GamePlayPanelShowOn',
                userInfo: GameManager.Instance.userInfo,
            });
        }
    }

    ShowOff()
    {
        this.node.active = false;

        if (cc.sys.platform == cc.sys.WECHAT_GAME) {
            wx.getOpenDataContext().postMessage({
                msg: 'GamePlayPanelShowOff',
                userInfo: GameManager.Instance.userInfo,
            });
        }
    }

    RefreshScore(_score:number)
    {
        if (cc.sys.platform == cc.sys.WECHAT_GAME) {
            wx.getOpenDataContext().postMessage({
                msg: 'RefreshScore',
                score: _score,
            });
        }
        // this.Label_score.string = _score.toString();

        // let highScore = cc.sys.localStorage.getItem('highScore' + GameType[GameManager.Instance.gameType]);
        // if (highScore == null) {
        //     highScore = 0;
        // }
        // if (_score > highScore) {
        //     highScore = _score;
        //     cc.sys.localStorage.setItem('highScore' + GameType[GameManager.Instance.gameType], highScore);
        // }
        // this.Label_highScore.string = highScore;
    }

    click_pause(button)
    {
        GameManager.Instance.gameState = GameState.Pause;
        SettingPanel.Instance.ShowOn(SettingPanelType.pause);
    }

}
